package com.bigknow.appstore.proxy.db;

import com.bigknow.appstore.proxy.entity.TCLog;
import com.bigknow.appstore.proxy.enumerate.SecurityType;
import com.mongodb.MongoClient;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;

import java.time.LocalDate;
import java.util.UUID;

/**
 * 构建测试用的数据库连接
 * Created by chaos on 2016/9/28.
 */
public final class DBFactory {

    public static final Datastore getDatastore(){
        Morphia morphia = new Morphia();
        return morphia.createDatastore(new MongoClient(), "appstore");
    }

    public static void main(String[] args) {
        Datastore ds = DBFactory.getDatastore();
        TCLog log = new TCLog();
        log.setId(UUID.randomUUID().toString());
        log.setResId("test1");
        log.setCurrentDate(LocalDate.now().toEpochDay());
        log.getCurrentValueOfDay().addAndGet(100);
        log.getCurrentValueOfMonth().addAndGet(100);
        log.getCurrentValueOfYear().addAndGet(100);
        log.setSecurityType(SecurityType.REC_CALL_TIMES_SEC);
        ds.save(log);
    }
}
